<?php

abstract class Quad_Db_Adapter_Abstract extends Quad_Observable implements Quad_Db_Adapter_Interface {
  
  public $_conn;
  
  public function __construct($connectInfo) {
    $connClass = self::_getConnClassName($connectInfo['adapter']);
    $this->_conn = new $connClass($connectInfo);
    $this->profiler = Quad_Profiler::getInstance('Database');
  }
  
  protected static function _getConnClassName($adapter) {
    return 'Quad_Db_Adapter_' . ucwords($adapter) . '_Conn';
  }
  
	public function connect() {
	  $this->_conn->connect();
    return (bool) $this->errorNo();
	}
  
	public function close();
	
	public function getStmt();
  
	public function quote($identifier);
	
	public function escape($value);
  
  public function query($sql, $bindVars=array());
  
  public function select($sql, $bindVars=array(), $offset=null, $limit=null);
  
  public function execute($sql, $bindVars=array()) {
  	$result = false;
  	try {
  		if ($this->isNotificationEnabled()) {
	  		$this->notify('execute', array(
	  			'queryType' => self::getQueryType($sql),
	  			'query' => self::normalizeSql($sql),
	  			'time' => date('Y-m-d H:i:s')
	  		));
  		}
 			$this->profiler->begin();
  		$result = $this->_conn->execute($sql, $bindVars);
  		$this->profiler->end(array('sql'=>$sql,'bindVars'=>$bindVars));
  	}
  	catch (Quad_Observable_Exception $ex) {}
  	return $result;
  }
  
  public function insert($sql, $bindVars=array());
  
  public function update($sql, $bindVars=array());
  
  public function delete($sql, $bindVars=array());
  
  public function errorMsg();
  
  public function errorNo();  
   
}